package com.flute.framework.data.mysql;


public final class SQL {
	private SelectSQL select;
	private WhereSQL where;
	private GroupBySQL groupBy;
	private OrderBySQL orderBy;
	private LimitSQL limit;

	public SelectSQL getSelect() {
		return select;
	}

	public void setSelect(SelectSQL select) {
		this.select = select;
	}

	public WhereSQL getWhere() {
		if (where == null) {
			where = new WhereSQL();
		}
		return where;
	}

	public void setWhere(WhereSQL where) {
		this.where = where;
	}

	public GroupBySQL getGroupBy() {
		if (groupBy == null) {
			groupBy = new GroupBySQL();
		}
		return groupBy;
	}

	public void setGroupBy(GroupBySQL groupBy) {
		this.groupBy = groupBy;
	}

	public OrderBySQL getOrderBy() {
		if (orderBy == null) {
			orderBy = new OrderBySQL();
		}
		return orderBy;
	}

	public void setOrderBy(OrderBySQL orderBy) {
		this.orderBy = orderBy;
	}

	public LimitSQL getLimit() {
		return limit;
	}

	public void setLimit(LimitSQL limit) {
		this.limit = limit;
	}

	public String toSQL(String table) {
		StringBuffer sb = new StringBuffer();
		sb.append(select.toSQL(table));
		if (where != null) {
			sb.append(where.toSQL());
		}
		if (groupBy != null) {
			sb.append(groupBy.toSQL());
		}
		if (orderBy != null) {
			sb.append(orderBy.toSQL());
		}
		if (limit != null) {
			sb.append(limit.toSQL());
		}

		return sb.toString();
	}
}
